<?php
/*
 * @param auther: feyeen Date: 2016/4/16 Time: 11:16
 * @param WapAddressWidget.php
 */

namespace common\widgets;

use Yii;
use common\models\AreaTable;
class WapAddressWidget extends \yii\bootstrap\Widget
{
    public $parent_id = '1';
    public $layer = '1';

    public function run(){
        //初始化数据
        parent::init();

        if($this->layer >3 || !is_numeric($this->layer))
            return false;

        if(!is_numeric($this->parent_id))
            return false;
        $AreaTable = new AreaTable();
        $str = '';
        switch($this->layer){
            case 0:
                $str ='';
                break;
            case 1:
                //加载运费配置文件


                $info =  $AreaTable->find()->where(['parent_id' =>$this->parent_id, 'layer' => $this->layer,'is_show'=>1])->asArray()->all();

                if(count($info)){
                    foreach($info as $key=>$val){
                        $str .='<li uid="'.$val['uid'].'"  >'.$val['name'].'</li>' ;//$val['name'];//<li dataid="1" liindex="1" class="">北京</li>
                    }
                }
                break;
            case 2:
                $info =  $AreaTable->find()->where(['parent_id' =>$this->parent_id, 'layer' => $this->layer])->asArray()->all();
                if(count($info)){
                    foreach($info as $key=>$val){
                        $str .='<li uid="'.$val['uid'].'"  >'.$val['name'].'</li>' ;//$val['name'];//<li dataid="1" liindex="1" class="">北京</li>
                    }
                }
                break;
            case 3:
                $info =  $AreaTable->find()->where(['parent_id' =>$this->parent_id, 'layer' => $this->layer])->asArray()->all();
                if(count($info)){
                    foreach($info as $key=>$val){
                        $str .='<li uid="'.$val['uid'].'"  >'.$val['name'].'</li>' ;//$val['name'];//<li dataid="1" liindex="1" class="">北京</li>
                    }
                }
                break;
        }
       return $str;

    }


}
